const shiftKey = [1, 2, 3, 5, 4]; // 密钥数组
function encryptCredentials() {
    const usernameField = document.getElementById("username");
    const passwordField = document.getElementById("password");

    const username = usernameField.value;
    const password = passwordField.value;
    let encryptedUsername = "";
    let encryptedPassword = "";
    for (let i = 0; i < username.length; i++) {
        let charCode = username.charCodeAt(i);
        charCode += shiftKey[i % shiftKey.length];
        encryptedUsername += String.fromCharCode(charCode);
    }
    for (let i = 0; i < password.length; i++) {
        let charCode = password.charCodeAt(i);
        charCode += shiftKey[i % shiftKey.length];
        encryptedPassword += String.fromCharCode(charCode);
    }
    // 简单加密逻辑（Base64）
    usernameField.value = encryptedUsername;
    passwordField.value = encryptedPassword;
}

function decryptCredentials() {
    const usernameField = document.getElementById("username");
    const passwordField = document.getElementById("password");
    const encryptedUsername = usernameField.value;
    const encryptedPassword = passwordField.value;
    let username = "";
    let password = "";
    for (let i = 0; i < encryptedUsername.length; i++) {
        let charCode = encryptedUsername.charCodeAt(i);
        charCode -= shiftKey[i % shiftKey.length];
        username += String.fromCharCode(charCode);
    }
    for (let i = 0; i < encryptedPassword.length; i++) {
        let charCode = encryptedPassword.charCodeAt(i);
        charCode -= shiftKey[i % shiftKey.length];
        password += String.fromCharCode(charCode);
    }

    usernameField.value = username;
    passwordField.value = password;
}